/*
ID: saboia
LANG: C++
TASK: ctiming
*/
//Accepted
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <iostream>
#include <list>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;


int main (){
	freopen("ctiming.in", "r", stdin);freopen("ctiming.out", "w", stdout);
	//freopen("in.txt", "r", stdin);
	int a, b, c, d, x;
	scanf("%d%d%d", &a, &b, &c);
	x=11*24*60+11*60+11;
	
	d=a*24*60+b*60+c;
	d-=x;
	if(d<0)printf("-1\n");
	else printf("%d\n", d);
	return 0;
}
